package com.wb.mas.ui.login;

import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import androidx.lifecycle.ViewModelProviders;

import com.wb.mas.BR;
import com.wb.mas.R;
import com.wb.mas.app.AppViewModelFactory;
import com.wb.mas.databinding.ActLoginByPhoneBinding;

import me.goldze.mvvmhabit.base.BaseActivity;

public class LoginByPhoneAc extends BaseActivity<ActLoginByPhoneBinding, LoginByPhoneViewModel> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.act_login_by_phone;
    }

    @Override
    public int initVariableId() {
        return BR.loginByPhoneViewModel;
    }


    @Override
    public LoginByPhoneViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(LoginByPhoneViewModel.class);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
//        viewModel.ui.btnCountingEvent.observe(this, new Observer() {
//            @Override
//            public void onChanged(Object o) {
//
//                binding.tvNextStep.setClickable(false);
//                binding.tvNextStep.setBackground();
//            }
//        });
//
//        viewModel.ui.btnNormalEvent.observe(this, new Observer() {
//            @Override
//            public void onChanged(Object o) {
//
//            }
//        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String preStr = getResources().getString(R.string.login_by_phone_agree_contract);

        String contentStr = getResources().getString(R.string.privacy_contract);

        String format = String.format(preStr, contentStr);

        SpannableString msp = new SpannableString(format);
        msp.setSpan(new ForegroundColorSpan(Color.parseColor("#3AAEFF")),
                format.length() - contentStr.length(),
                format.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        binding.tvLoginHint.setText(msp);

    }
}
